package com.tech.koufu.model;

import java.util.ArrayList;
import java.util.Arrays;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.os.Parcel;
import android.os.Parcelable;
import android.os.Parcelable.Creator;
import android.text.TextUtils;
import android.util.Log;

/**
 * 大赛对象
 * @author jl_luo
 *
 */
public class CompetitionGroup implements android.os.Parcelable{

	 public String groupId;
	 public String name;
	 public String memberQuantity;
	 public String cover;
	 public String addTime;
	 public String userName;
	 public ArrayList<CompetitionNotice> notices = new ArrayList<CompetitionNotice>();
	 
	 public CompetitionGroup(){
		 
	 }
	 public CompetitionGroup(JSONObject object){
		 this.groupId = object.optString("group_id");
		 this.name = object.optString("name");
		 this.memberQuantity = object.optString("member_quantity");
		 this.cover = object.optString("cover");
		 this.addTime = object.optString("add_time");
		 this.userName = object.optString("user_name");
		 String ns = object.optString("notice");
		 if(!TextUtils.isEmpty(ns) && !ns.equals("null")){
			 try {
				JSONArray noticeArry = object.getJSONArray("notice");
				int length = noticeArry.length();
				notices = new ArrayList<CompetitionNotice>();
				for(int i=0;i<length;i++){ 
					CompetitionNotice notice = new CompetitionNotice(noticeArry.getJSONObject(i));
					notices.add(notice);
				}
			} catch (JSONException e) { 
				e.printStackTrace();
			}
		 }
	 }
	 public CompetitionGroup(Parcel parcel){
		 this.groupId = parcel.readString();
		 this.name = parcel.readString();
		 this.memberQuantity = parcel.readString();
		 this.cover = parcel.readString();
		 this.addTime = parcel.readString();
		 this.userName = parcel.readString();  
			 parcel.readList(notices, CompetitionNotice.class.getClassLoader());
	 }
	 public static final Parcelable.Creator<CompetitionGroup> CREATOR = new Creator<CompetitionGroup>() {

			@Override
			public CompetitionGroup createFromParcel(Parcel source) { 
				return new CompetitionGroup(source);
			}

			@Override
			public CompetitionGroup[] newArray(int size) { 
				return new CompetitionGroup[size];
			}
		};
	@Override
	public int describeContents() { 
		return 0;
	}

	@Override
	public void writeToParcel(Parcel dest, int flags) { 
		dest.writeString(groupId);
		dest.writeString(name);
		dest.writeString(memberQuantity) ;
		dest.writeString(cover);
		dest.writeString(addTime);
		dest.writeString(userName); 
			dest.writeList(notices); 
	}
	 
}
